axios.get('/index/index').then(({data:{data}, status}) => {
    // console.log(data, status)
    const {allCate,sideBanner,allTag, allLink} = data

    if(status !== 200){
        return layer.msg('获取信息失败')
    }
    // layer.msg('获取信息成功')

    // 表头所有分类部分    
    const navLi = allCate.map(({id, icon, catename}) => {
        // console.log(item)
        return `
        <li class="menu-item menu-item-type-taxonomy menu-item-object-category"><a href="" id="${id}">
        <span class="fa ${icon}"></span>${catename}</a></li>`  
    }).join('')
    // console.log(navLi)
    $('.nav').append(navLi)
    $('.nav').on('click', '.menu-item a', function(e){
        e.preventDefault()
        $(this).css({'color':'#ff5e52'}).parent().siblings().children('a').css({'color':'#666'})
    })

    // 右边侧边栏
    const nofollowLi = sideBanner.map(({advimglink, advimgdesc, advimgsrc}) => {
        // console.log(res)
        return `
        <a href="${advimglink}" rel="nofollow" target="_blank" title="${advimgdesc}">
            <img class="g430" style="width:360px;height:133px;" src="http://124.223.14.236:8060/${advimgsrc}" alt="阿里云开学季" >
        </a>`
    }).join('')
    $('.textwidget').html(nofollowLi)

    // 热门标签
    const biaoqian = allTag.map(({id, tagname}) => {
        // console.log(res)
        return `<li><a title="" href="" id="${id}">${tagname}</a></li>`
    }).join('')
    $('.widget_tags_inner').html(biaoqian)

    // 友情链接部分
    const frend = allLink.map(({url, img, title, des}) => {
        // console.log(res)
        return `
        <li>
        <a href="${url}"><img src="http://124.223.14.236:8060/${img}" alt="" title="${title}">
          <p>${des}</p>
        </a>
      </li>`
    }).join('')

    $('.widget_comments ul').html(frend)
})

// 热门文章部分
axios.get('/index/recommend').then(({data:{data}}) => {
    // console.log(data)
    const {list} = data
    const rewen = list.map(({pic, title, click}) => {
        // console.log(res)
        return `
        <li>
        <a target="_blank" href="">
          <span class="thumbnail">
            <img src="http://124.223.14.236:8060/${pic}" class="thumb" />
          </span>
          <span class="text">${title}</span>
          <span class="text-muted post-views">阅读(${click})</span>
        </a>
      </li>`
    }).join('')

    $('.widget_postlist .items-02').html(rewen)
})

// 最新文章部分
axios.get('/index/hot').then(({data:{data}}) => {
    // console.log(data)
    const {list} = data
    const newText = list.map(({pic, title, lovenum}) => {
        // console.log(pic)
        return `
            <li>
            <a target="_blank" href="">
              <span class="thumbnail">
                <img class="thumb" src="http://124.223.14.236:8060/${pic}" />
              </span>
              <span class="text">${title}</span>
              <span class="text-muted post-views">阅读(${lovenum})</span>
            </a>
            </li>`
    }).join('')
    $('.widget_postlist .items-01').html(newText)
})